/*
 * @Descripttion:
 * @Author: Wang Dejiang(aei)
 * @Date: 2022-07-31 19:35:42
 * @LastEditors: Wang Dejiang(aei)
 * @LastEditTime: 2022-08-03 23:35:11
 */
import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import Blog from "../views/Blog/Blog.vue";
import BlogCreate from "../views/Blog/BlogCreate.vue";
import BlogList from "../views/Blog/BlogList.vue";
import BlogShow from "../views/Blog/BlogShow.vue";
import NProgress from "nprogress";
import store from "@/store/store";
import Chat from "@/views/Chat/Chat";
import Form from "@/views/Form";
import Goods from "@/views/Goods";
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/blog",
    // name: "blog",
    component: Blog,
    children: [
      {
        path: "",
        name: "blog-list",
        component: BlogList,
        props: true,
      },
      {
        path: "blogpost/:id",
        name: "blog-show",
        component: BlogShow,
        // props: true,
        // beforeEnter(routeTo, routeFrom, next) {
        //   store
        //     .dispatch("blogpost/fetchBlog", routeTo.params.id)
        //     .then((blogpost) => {
        //       console.log(111, blogpost);
        //       routeTo.params.blogpost = blogpost;
        //       next();
        //     })
        //     .catch((error) => {
        //       console.log(error);
        //     });
        // },
      },
      {
        path: "blogposts/create",
        name: "blog-create",
        component: BlogCreate,
      },
    ],
  },
  {
    path: "/chat",
    name: "chat",
    component: Chat,
  },
  {
    path: "/form",
    name: "form",
    component: Form,
  },
  {
    path: "/goods",
    name: "goods",
    component: Goods,
  },
];

const router = new VueRouter({
  base: '/web/',
  routes,
});

router.beforeEach((routeTo, routeFrom, next) => {
  NProgress.start();
  next();
});

router.afterEach(() => {
  NProgress.done();
});

export default router;
